package storm2;// -*- codeing: utf-8 -*-

// @Time     :2021/12/10 11:55
// @Author   :郭荣杰
//@File      :StormRedis.java
//@Software  : IntelliJ IDEA

import org.apache.storm.topology.BasicOutputCollector;
import org.apache.storm.topology.OutputFieldsDeclarer;
import org.apache.storm.topology.base.BaseBasicBolt;
import org.apache.storm.tuple.Tuple;


/**     实现功能
 * *（4） 展示截止当前时间的总销售金额、订单数量、下单客户数基本信息；
 *  存储在redis Top10Books
 *
 *        展示不同类型课本销售额
 */
public class Bolt_TotalSales extends BaseBasicBolt {
    //127.0.0.1
    //192.168.179.140
    static  JRedisUtil jredis = new JRedisUtil("127.0.0.1",6379);
    public void execute(Tuple input, BasicOutputCollector collector) {
        try{
            /**
             *      得到订单总费用，统计实现总销售金额
             *      实现统计总订单数量
             *      得到收件人姓名，统计下单客户数
             *      得到支付方式，统计每种支付方式下单量
             *      得到收件地址，统计各地下单量
             *      得到发件地址，统计各地发货量
             */
            double one_sale=input.getDoubleByField("total");
            String recipient=input.getStringByField("recipient");
            String payment = input.getStringByField("methodofpayment");
            String place=input.getStringByField("receiveplace");
            String sendplace=input.getStringByField("sendplace");

            jredis.incrBy("TotalSales",one_sale);
            jredis.incrBy("TotalOrders",1);
            jredis.zincrby("UserOrderNum",1,recipient);
            jredis.zincrby("Payment",1,payment);
            jredis.zincrby("PlaceOrdersNum",1,place.substring(0,2));
            jredis.zincrby("SendPlaceOrdersNum",1,sendplace.substring(0,2));
        }catch (Exception e){
//            e.printStackTrace();
            System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
        }
        finally {
            System.out.println("*************************************");
        }
    }

    public void declareOutputFields(OutputFieldsDeclarer declarer) {

    }
}